package com.example.weather.title

import android.Manifest
import android.content.Intent
import android.net.Uri
import android.util.SparseArray
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.library_base.base.BaseActivity
import com.example.library_base.router.WeatherRouterPath
import com.example.weather.R
import dagger.hilt.android.AndroidEntryPoint
import permissions.dispatcher.NeedsPermission
import permissions.dispatcher.OnShowRationale
import permissions.dispatcher.PermissionRequest
import permissions.dispatcher.RuntimePermissions
import javax.inject.Inject

@RuntimePermissions
@AndroidEntryPoint
@Route(path = WeatherRouterPath.WEATHER_TITLE)
class TitleActivity: BaseActivity(R.layout.activity_title) {

    @Inject
    lateinit var titleModel: TitleModel

    override fun getVariableSparseArray(): SparseArray<Any> {
        val variables = SparseArray<Any>()
        return variables
    }

    override fun initTitleBar() {
        super.initTitleBar()
        supportActionBar?.title = "标题"
    }

    override fun initView() {
        callPhoneWithPermissionCheck()
    }

    override fun requestData() {

    }

    @NeedsPermission(Manifest.permission.CALL_PHONE)
    fun callPhone() {
        val intent = Intent(Intent.ACTION_CALL)
        val data = Uri.parse("tel:13641203361")
        intent.data = data
        startActivity(intent)
    }

    override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,
        grantResults: IntArray
    ) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        onRequestPermissionsResult(requestCode, grantResults)
    }

    @OnShowRationale(Manifest.permission.CALL_PHONE)
    fun showCallPhone(request: PermissionRequest) {
    }


}